package com.ruoyi.qxk.rabmq.config;


import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @className: Helpp
 * @author: xikun
 * @date: 2025/5/21 20:53
 * @Version: 1.0
 * @description:
 */
@Configuration
public class Helpp {
    @Bean("HelpMessageConverter")  // 添加唯一名称
    public MessageConverter HelpMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }
    //声明正常交换机
    @Bean
    public Exchange HelpExchange1() {
        return ExchangeBuilder.topicExchange("Help_exchange1").durable(true).build();
    }
    //  声明正常队列
    @Bean
    public Queue HelpQueue1() {
        return QueueBuilder.durable("Help_queue1")
                .deadLetterExchange("Help_exchange2")//正常队列绑定死信交换机
                .deadLetterRoutingKey("Help.#")//正常队列绑定死信路由键
               .ttl(60*1000)  //设置消息的过期时间
               .build();
    }
    //  绑定正常交换机和正常队列
    @Bean
    public Binding HelpBinding1() {
        return BindingBuilder.bind(HelpQueue1()).to(HelpExchange1()).with("Help.#").noargs();
    }
    //声明死信交换机
    @Bean
    public Exchange HelpExchange2() {
        return ExchangeBuilder.topicExchange("Help_exchange2").durable(true).build();
    }
    //声明死信队列
    @Bean
    public Queue HelpQueue2() {
        return QueueBuilder.durable("Help_queue2").build();
    }
    //  绑定死信交换机和死信队列
    @Bean
    public Binding HelpBinding2() {
        return BindingBuilder.bind(HelpQueue2()).to(HelpExchange2()).with("Help.#").noargs();
    }
}
